var count = 0;
var router = new VueRouter({
			routes:[{path: '/',
                    	redirect: '/message'
                    },{
						path:'/message',
						component:{
							template:'#message_view',
              data:function (){
                  return{

                  }
              },
              created:function (){
                //this.$parent.issend=0;
              },
              mounted:function (){
                var v = this.$parent;
                var btns = document.getElementsByClassName("btn");
                //选择收件箱和发件箱
                for(var i = 0; i < btns.length; i++) {
                    btns[i].onclick = function(){
                      for(var i = 0; i < btns.length; i++){
                        if(btns[i]==this) v.issend=i;
                      }
                    }
                }
 
              },
              methods:{
                
              },
						}
					},{
						path:'/contact',
						component:{
							template:'#contact_view',
							data:function (){
              					return{
              					   
              					}
           					}
						}
					},{
						path:'/set',
						component:{
							template:'#set_view',
                            data:function (){
                                return{
                                  
                                }
                            },
                            created:function (){
                              
                            },
							methods:{
							    
              },
						}
					}]
		})
    
		var vue = new Vue({
			el:'.view_box',
			router: router,
      data:{
        userID:'',
        icon:'',
        issend:0,
        allMail:[],
        allAddress:[],
        searchName:'',
      },
      created:function (){
        this.userID=window.android.getUserId();
        //this.icon=window.android.getIcon(window.android.icon);
        //console.log(window.android.icon);
      },
      methods:{
        //刷新邮件
        refreshMail:function(jsonArray){
          var json = JSON.stringify(jsonArray, null, 4)
          this.allMail=JSON.parse(json).data;
          //console.log(this.allMail)
        },isopen:function(is){
          //判定邮件是否查看过
            if(is==1)return "file:///android_res/drawable/ic_mail_unwatch.png";
            else return "file:///android_res/drawable/ic_mail_watch.png";
        },//刷新邮件
        refreshAddress:function(jsonArray){
          var json = JSON.stringify(jsonArray, null, 4)
          this.allAddress=JSON.parse(json).data;
          //console.log(this.allAddress)
        },refreshIcon:function(icon){
          this.icon = window.android.getIcon(icon);
          //console.log(this.icon)
        },test:function(){
          console.log(1);
        }
      }
		});
    window.refreshMail= function(jsonArray){
      vue.refreshMail(jsonArray);
    }
    window.refreshAddress= function(jsonArray){
      vue.refreshAddress(jsonArray);
    }
    window.refreshIcon= function(icon){
      //console.log(icon);
      vue.refreshIcon(icon);
    }
    //打开邮件
    window.toMessage = function(Mail,from){
      if(count == 0){
        Mail.issend = 0;
        window.android.toMessage(Mail.eid,from);
        count = 1;
      
          flag=setTimeout(function(){
              count = 0;
          },300); 
      }
    }
    //编辑通讯录
    window.toUpdateAddress = function(friend){
      if(count == 0){
        window.android.toUpdateAddress(friend.aid,friend.user2,friend.nickname,friend.icon,1);
        count = 1;
      
          flag=setTimeout(function(){
              count = 0;
          },300); 
      }
    }
    //发给指定人
    window.toSendMessage = function(user2){
      if(count == 0){
        window.android.toSendMessage(user2)
        count = 1;
      
          flag=setTimeout(function(){
              count = 0;
          },300); 
      }
    }
    //更新个人信息
    window.toUpdateUser = function(){
      if(count == 0){
        window.android.toUpdateUser()
        count = 1;
      
          flag=setTimeout(function(){
              count = 0;
          },300); 
      }
    }
    //清空图片
    window.clearImg = function(){
      if(count == 0){
        window.android.clearImg()
        count = 1;
      
          flag=setTimeout(function(){
              count = 0;
          },300); 
      }
    }
    //收藏夹
    window.toCollection = function(){
      if(count == 0){
        window.android.toCollection()
        count = 1;
      
          flag=setTimeout(function(){
              count = 0;
          },300); 
      }
    }
    //注销
    window.logoff = function(){
      if(count == 0){
        window.android.logoff()
        count = 1;
      
          flag=setTimeout(function(){
              count = 0;
          },300); 
      }
    }